package com.adapter.adapterUsedInMVC;

public interface HandlerAdapter {
    public boolean supports(Object handler );

    public void handle(Object handler);
}

//各个适配器感觉这些适配器就是把handler(Object)转为具体的Controller对象
class HttpHandlerAdapter implements HandlerAdapter{

    //判断是否是某个Controller的实例，如果是实例才可以调用Controller中的方法
    @Override
    public boolean supports(Object handler) {
        return  handler instanceof  HttpController ;
    }

    @Override
    public void handle(Object handler) {
        ((HttpController)handler).doHttpController();
    }
}

class SimpleHandlerAdapter implements HandlerAdapter{

    //判断是否是某个Controller的实例，如果是实例才可以调用Controller中的方法
    @Override
    public boolean supports(Object handler) {
        return  handler instanceof  SimpleController ;
    }

    @Override
    public void handle(Object handler) {
        ((SimpleController)handler).doSimpleController();
    }
}

class AnnotationHandlerAdapter implements HandlerAdapter{

    //判断是否是某个Controller的实例，如果是实例才可以调用Controller中的方法
    @Override
    public boolean supports(Object handler) {
        return  handler instanceof  AnnotationController ;
    }

    @Override
    public void handle(Object handler) {
        ((AnnotationController)handler).doAnnotationController();
    }
}


